<template>
  <div class="app-container org">
    <el-card>
      <el-row>
        <el-col :span="24">
          <p class="pinformation">搜索条件</p>
        </el-col>
      </el-row>
      <el-form ref="queryRef" label-width="100" :model="queryParams">
        <el-row>
          <el-col :span="3">
            <el-form-item label="入库批次编号：" prop="wxfwCode">
              <el-input
                clearable
                maxlength="100"
                placeholder="请输入入库批次编号"
                v-model="queryParams.wxfwCode"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item
              label="容器/包装编码："
              prop="containerCode"
              label-width="115"
            >
              <el-input
                clearable
                maxlength="100"
                placeholder="请输入"
                v-model="queryParams.containerCode"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item
              label="危险品俗称/名录名称："
              prop="wxfwName"
              label-width="150"
            >
              <el-input
                clearable
                maxlength="100"
                placeholder="请输入"
                v-model="queryParams.wxfwName"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item label="危废类别：" prop="wxfwType" label-width="80">
              <el-select
                placeholder="请选择"
                clearable
                v-model="queryParams.wxfwType"
                filterable
              >
                <el-option
                  v-for="dict in proxy.addListNoLimit(wxfw_type)"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-form-item label="危废代码：" prop="wxfwNumber" label-width="80">
              <el-input
                clearable
                maxlength="100"
                placeholder="请输入"
                v-model="queryParams.wxfwNumber"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="入库日期：" prop="createDate" label-width="80">
              <el-date-picker
                v-model="dateRange"
                value-format="YYYY-MM-DD"
                type="daterange"
                :clearable="false"
                :editable="false"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-form-item label="入库人：" prop="wxfwUser" label-width="60">
              <el-input
                clearable
                maxlength="100"
                placeholder="请输入"
                v-model="queryParams.wxfwUser"
                @keyup.enter="handleQuery"
              />
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-row justify="center">
              <el-button type="success" @click="handleQuery">搜索</el-button>
              <el-button class="resetBtn" @click="resetQuery">重置</el-button>
            </el-row>
          </el-col>
        </el-row>
      </el-form>
      <el-row>
        <p class="pinformation">危险废物入库列表</p>
        <p class="totalStyle">共 {{ total }} 条数据</p>
        <!-- <el-button
          type="success"
          style="padding-bottom: 8px; margin-left: 10px"
          link
          icon="Plus"
          @click="importTemplate"
          >导出台账</el-button
        > -->
        <el-table ref="mainTableRef" :data="wxfwTable" v-loading="loading">
          <el-table-column
            show-overflow-tooltip
            label="入库批次编号"
            prop="wxfwCode"
            align="center"
            width="110"
          />
          <el-table-column
            show-overflow-tooltip
            label="入库时间"
            prop="createDate"
            align="center"
            width="100"
          />
          <el-table-column
            show-overflow-tooltip
            label="容器/包装编码"
            prop="containerCode"
            align="center"
            width="120"
          />
          <el-table-column
            show-overflow-tooltip
            label="容器/包装类型"
            prop="containerTypeName"
            align="center"
            width="120"
          />
          <el-table-column
            show-overflow-tooltip
            label="容器/包装数量"
            prop="containerCount"
            align="center"
            width="120"
          />
          <el-table-column
            show-overflow-tooltip
            label="内部名称"
            prop="internalName"
            align="center"
          />
          <el-table-column
            show-overflow-tooltip
            label="国家名录名称"
            prop="coudirName"
            align="center"
          />
          <el-table-column
            show-overflow-tooltip
            label="危废类别"
            prop="wxfwTypeName"
            align="center"
            width="80"
          />
          <el-table-column
            show-overflow-tooltip
            label="危废代码"
            prop="wxfwNumber"
            align="center"
            width="80"
          />
          <el-table-column
            show-overflow-tooltip
            label="库存量"
            prop="remainCount"
            align="center"
            width="80"
          />
          <el-table-column
            show-overflow-tooltip
            label="计量单位"
            prop="unitName"
            align="center"
          >
            <template #default="scope">
              <span v-html="transformation(scope.row.unitName)"></span>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            label="运送部门经办人"
            prop="transportUser"
            align="center"
          />
          <el-table-column
            show-overflow-tooltip
            label="贮存部门经办人"
            prop="storageUser"
            align="center"
          />
          <el-table-column
            show-overflow-tooltip
            label="产生批次编码"
            prop="batchCode"
            align="center"
          />
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </el-row>
    </el-card>
    <!-- 单个入库和引用弹窗 -->
  </div>
</template>

<script setup name="WxfwOutin">
import {
  newlistLedger,
} from "@/api/resource/wxfw";

const { proxy } = getCurrentInstance();
const { wxfw_type } = proxy.useDict(
  "wxfw_type",
);

const wxfwTable = ref([]);
const loading = ref(false);
const data = reactive({
  queryParams: {
    pageNum: 1, // 当前页数
    pageSize: 10, // 当前页数据条数
    wxfwType: -1,
    status: -1,
  },
});

const { queryParams } = toRefs(data);

const heightParams = ref([{ tableName: "main", bottomHeight: 21 }]);

function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}
onMounted(() => {
  nextTick(() => {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});
onUpdated(() => {
  nextTick(function () {
    getTableHeight();
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

const total = ref(0);
const dateRange = ref([]);
function getList() {
  loading.value = true;
  newlistLedger(proxy.addDateRange(queryParams.value, dateRange.value)).then(
    (res) => {
      wxfwTable.value = res.rows;
      loading.value = false;
      total.value = res.total;
    }
  );
}
getList();

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "main", bottomHeight: 73 }];
    } else {
      heightParams.value = [{ tableName: "main", bottomHeight: 21 }];
    }
    getTableHeight();
  }
);

function transformation(row) {
  return proxy.getSupAndSub(row);
}

// serialTypeId.value = 38

/** 下载模板操作 */
function importTemplate() {
  return;
  proxy.download(
    "/resource/bzwz/importTemplate",
    {},
    `危险废物模板_${new Date().getTime()}.xlsx`
  );
}


</script>

<style lang="scss" scoped>
.el-radio {
  margin-right: 5px;
}
</style>
